﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="renderer" content="webkit" />
    <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="360-site-verification" content="232fd13e627a76e18f104ec80281dd2c" />
    <meta name="renderer" content="webkit">
    <meta name="x5-orientation" content="portrait">
    <meta name="x5-fullscreen" content="true">
    <meta name="screen-orientation" content="portrait">
    <meta name="full-screen" content="yes">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">
    <meta http-equiv="Cache-Control" content="no-siteapp">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <title>绑定授权页面</title>
    <link href="../Common/layim/dist/css/layui.css" rel="stylesheet" />
    <link href="../Common/layim/plugin/weixin/css/login.css" rel="stylesheet" />
    <link href="../Common/layim/plugin/weixin/css/main.css" rel="stylesheet" />
    <link href="../Common/layim/plugin/weixin/css/animate.min.css" rel="stylesheet" />
    <link href="../Common/layim/plugin/weixin/css/main.css" rel="stylesheet" />
    <link href="../Common/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
    <link href="../Common/bootstrap/css/font-awesome.min.css" rel="stylesheet" />
    <link href="../Common/bootstrap/css/material-design-iconic-font.min.css" rel="stylesheet" />

</head>
<body>
    <div class="limiter">
        <div class="container-login100" style="background-image: url('../images/timg.jpg');">
            <div class="wrap-login100 p-l-55 p-r-55 p-t-65 p-b-54">
                <form class="login100-form validate-form">
                    <div style="text-align: center;">
                        LOGO
                        <!--<img style="    width: 100%;height: auto;" src="/wwwroot/images/logo.png">-->    <br />
                    </div>
                    <br />
                    <p style="color:red;text-align:center">首次使用请绑定帐号！</p>
                    <div class="wrap-input100 validate-input m-b-23" data-validate="请输入用户名">
                        <span class="label-input100">用户名</span>
                        <input class="input100" type="text" name="username" id="username" placeholder="请输入用户名" autocomplete="off">
                        <span class="focus-input100" data-symbol="&#xf206;"></span>
                    </div>

                    <div class="wrap-input100 validate-input" data-validate="请输入密码">
                        <span class="label-input100">密码</span>
                        <input class="input100" type="password" name="pass" id="pass" placeholder="请输入密码">
                        <span class="focus-input100" data-symbol="&#xf190;"></span>
                    </div>

                    <div class="text-right p-t-8 p-b-31">
                        <a href="javascript:"></a>
                    </div>

                    <div class="container-login100-form-btn">
                        <div class="wrap-login100-form-btn">
                            <div class="login100-form-bgbtn"></div>
                            <button class="login100-form-btn">绑  定</button>
                        </div>
                    </div>
                    <div class="flex-col-c p-t-25">
                    </div>
                </form>
            </div>
        </div>
    </div>
    <script src="../Common/layim/dist/layui.all.js"></script>
    <script>
        //定义全局变量
        weixin = new Object();
        layui.config({
            base: '../Common/layim/layui_exts/' //指定 插件 路径
            , version: '1.0.0-beta'
        }).define(['table', 'jquery', 'form', 'layer', 'laydate', 'common', 'upload'], function (exports) {
            var common = layui.common,layer = layui.layer;
            var strUser = common.getRequest().strUser;
            if (strUser != null) {
                strUser = unescape(strUser);
                weixin = JSON.parse(strUser);
            } else {
                //回到首页重新授权
                window.location.href = "weixin.html";
            }

            $ = layui.$; jQuery = layui.$;
(function ($) {
    "use strict";


    /*==================================================================
   [ Focus input ]*/
    $('.input100').each(function () {
        $(this).on('blur', function () {
            if ($(this).val().trim() != "") {
                $(this).addClass('has-val');
            }
            else {
                $(this).removeClass('has-val');
            }
        })
    })


    /*==================================================================
    [ Validate ]*/
    var input = $('.validate-input .input100');

    $('.validate-form').on('submit', function () {
        var check = true;

        for (var i = 0; i < input.length; i++) {
            if (validate(input[i]) == false) {
                showValidate(input[i]);
                check = false;
            }
        }

            if (check) {
                var username = $("#username").val();
                var pass = $("#pass").val();
                var lay = layer.msg('正在绑定...', { icon: 16, shade: 0.5, time: 20000000 });
                var openid = weixin.openid;
                $.ajax({
                    type: "post",
                    url: "/login/wxlogin",
                    data: { username: username, password: pass ,openid:openid},
                    dataType: "json",
                    success: function (data) {
                   
                        layer.close(lay);
                        //layer.alert(data);
                        if (data.success) {
               window.localStorage["user"] = data.name;
                window.localStorage["userid"] = data.userid;
                window.localStorage["orname"] = data.orname;
                window.localStorage["orid"] = data.orid;
                window.localStorage["_token"] = data.access_token;
                window.localStorage["account"] = data.account;
                window.localStorage["role"] = data.role;
                window.localStorage["picture"] = data.picture;
                window.location.href = "/weixin.html";
                       
                        } else {
                            layer.alert(data.responseText);
                        
                        }
                    },
                    error: function (ex) {
                        layer.msg(ex.message);
                       layer.alert("发生错误:" + ex.statusText, {title:"温馨提示！"});
                        layer.close(lay);

                    }
                });
                return false;
            }
 
        return false;
    });


    $('.validate-form .input100').each(function () {
        $(this).focus(function () {
            hideValidate(this);
        });
    });

    function validate(input) {
        if ($(input).attr('type') == 'email' || $(input).attr('name') == 'email') {
            if ($(input).val().trim().match(/^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{1,5}|[0-9]{1,3})(\]?)$/) == null) {
                return false;
            }
        }
        else {
            if ($(input).val().trim() == '') {
                return false;
            }
        }

    }

    function showValidate(input) {
        var thisAlert = $(input).parent();

        $(thisAlert).addClass('alert-validate');
    }

    function hideValidate(input) {
        var thisAlert = $(input).parent();

        $(thisAlert).removeClass('alert-validate');
    }



})(jQuery);
        })
    </script>
</body>
</html>